#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

class dTree {
private:
    struct node {
        int code;
        int value;
    };
    struct lnode {
        int len;
        int xlen;
        int del;
        int leaf;
        node *children;
    };
    lnode *tree;
    int r0;
    int n;
    int d;
public:
    dTree(int a, int b) {
        n = a;
        d = b;
        tree = new lnode[a];
        node *p;
        int i, j, chx, k;
        for (i = 0; i < a; i++) tree[i].children = NULL;
        for (i = 0; i < a; i++) {
            cin >> chx;
            tree[i].del = 0;
            tree[i].xlen = 0;
            for (j = 0; j < chx; j++) {
                p = new node;
                cin >> k;
                p->code = i;
                cin >> p->value;
                tree[k].children = p;
            }
        }
    }

    void leafandlen() {
        node *p;
        int i, x, y;
        for (i = 0; i < n; i++) {
            if (tree[i].del == 0) {
                p = tree[i].children;
                x = 0;
                tree[i].len = 0;
                tree[i].xlen = 0;
                tree[i].leaf = 1;
                while (p != NULL) {
                    x = x + p->value;
                    tree[i].len = x;
                    tree[p->code].leaf = 0;
                    p = tree[p->code].children;
                }
            }
        }
        for (i = 0; i < n; i++) {
            if (tree[i].del == 0) {
                if (tree[i].leaf == 1) {
                    p = tree[i].children;
                    while (p != NULL) {
                        y = tree[i].len - tree[p->code].len;
                        if (tree[p->code].xlen < y) tree[p->code].xlen = y;
                        p = tree[p->code].children;
                    }
                }
            }
        }
        //for(int i=0;i<n;i++) cout<<tree[i].del<<" leaf"<<tree[i].leaf<<" xlen"<<tree[i].xlen<<" len"<<tree[i].len<<endl;
    }

    void solution0() {
        node *p;
        int i, k, r = 0;
        k = 1;
        while (k == 1) {
            leafandlen();
            k = 0;
            for (i = 0; i < n; i++) {
                if (tree[i].del == 0 && tree[i].len > d) {
                    k = 1;
                    break;
                }
            }
            //cout<<k<<endl;
            for (i = 0; i < n; i++) {
                if (tree[i].del == 0 && tree[i].leaf == 1 && tree[i].len > d) {
                    p = tree[i].children;
                    while (p != NULL) {
                        if (tree[p->code].del == 1) break;
                        if (tree[p->code].xlen > d) break;
                        else p = tree[p->code].children;
                    }
                    if (p != NULL) {
                        if (tree[p->code].xlen > d && tree[p->code].del == 0) {
                            tree[p->code].del = 1;
                            cout << "[X]Node" << p->code << "" << endl;
                            r++;
                            r0 = r;
                        }
                    }
                }
            }
            //cout<<r<<endl;
            for (i = 0; i < n; i++) {
                if (tree[i].del == 0) {
                    p = tree[i].children;
                    if (p != NULL) {
                        if (tree[p->code].del == 1) {
                            tree[i].children = NULL;
                            delete p;
                        }
                    }
                }
            }
        }
    }

    void solution() {
        solution0();
        cout << r0;
    }
};

int main() {
    int n, d;
    cin >> n >> d;
    dTree dt(n, d);
    dt.solution();
    return 0;
}
/*
5 5
3 1 4 2 9 3 2
0
1 4 5
0
0

100 32
2 1 81 2 5
2 3 17 4 99
2 5 31 6 34
2 7 29 8 2
2 9 62 10 43
2 11 54 12 79
2 13 42 14 93
2 15 21 16 10
2 17 38 18 22
2 19 36 20 70
2 21 50 22 22
2 23 1 24 57
2 25 83 26 36
2 27 80 28 93
2 29 54 30 16
2 31 83 32 32
2 33 67 34 21
2 35 23 36 42
2 37 75 38 81
2 39 54 40 62
2 41 15 42 64
2 43 7 44 65
2 45 39 46 8
2 47 4 48 8
2 49 27 50 90
2 51 19 52 88
2 53 25 54 37
2 55 11 56 69
2 57 19 58 82
2 59 1 60 59
2 61 74 62 4
2 63 21 64 23
2 65 18 66 97
2 67 42 68 79
2 69 51 70 49
2 71 55 72 24
2 73 95 74 3
2 75 52 76 37
2 77 48 78 46
2 79 19 80 33
2 81 60 82 59
2 83 42 84 41
2 85 58 86 27
2 87 21 88 87
2 89 56 90 67
2 91 16 92 6
2 93 91 94 55
2 95 40 96 67
2 97 27 98 31
1 99 81
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
*/